<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var str = 'abcoefoxyozzopp';
        var obj = {};
        for (var i = 0; i < str.length; i++){
            var code = str[i];
            if(obj[code]){
                obj[code] = obj[code] + 1;
            }else{
                obj[code] = 1;
            }
        }
        console.log(obj); //{a: 1, b: 1, c: 1, o: 4, e: 1, …}

        //遍历对象
        var max = 0;
        var k = ''
        for(var key in obj){
            // console.log(obj[key]); 
            if(obj[key] > max){
                max = obj[key];
                k = key;
            }
        }
        console.log(max,k); //4 "o"
    </script>
</body>
</html>